<template>
	<view class="wrap">
		<uv-checkbox-group v-model="field.__answer__.value" @change="control_change" wrap placement="column">
			<uv-checkbox v-for="(item, index) in field.csmwjoptions.options" :key="index"
				:label="item.value+ ((field.csmwjshowscore.showscore===true && field.csmwjshowscore.method==='everyscore' && item.score!=null)?(' ('+item.score+' '+$t('csmwj.label.score')+')'):'')"
				:name="item.value" :data-score="item.score"  :customStyle="{margin: '4px'}"
				:labelColor="(paper.themeoptionsfontcolor!=null&&paper.themeoptionsfontcolor!='')?paper.themeoptionsfontcolor:''"
				:activeColor="(paper.themeoptionsselectedcolor!=null&&paper.themeoptionsselectedcolor!='')?paper.themeoptionsselectedcolor:''">
			</uv-checkbox>
		</uv-checkbox-group>
	</view>
</template>

<script>
	import config from "@/config/config.js";
	import xcHttpUtils from '@/library/xcore/js/XcHttpUtils.js';
	import xcViewUtils from '@/library/xcore/js/XcViewUtils.js';
	import {
		xsStringUtils,
		xsDateUtils,
		xsArrayUtils
	} from 'xstack-for-javascript';

	export default {
		props: {
			field: {
				type: Object,
				default: []
			},
			paper: {
				type: Object,
				default: []
			},
		},
		watch: {
			'field': {
				handler(newVal, oldVal) {
					let that = this;
					that.public_reset();
				},
			},
		},
		emits: ['change'],
		data() {
			return {
				checkboxValue: [],
				config: config,
				xsStringUtils: xsStringUtils,
				xsDateUtils: xsDateUtils,
				sp: {},
				sr: {},
				control: {}
			}
		},
		created() {
			let that = this;
			that.xinit();
			that.public_show();
		},
		methods: {
			xinit() {
				let that = this;
			},
			public_show() {
				let that = this;
				that.field.__answer__.value = (that.field.__answer__.value)?that.field.__answer__.value:[];
				
			},
			public_reset() {
				let that = this;
				that.public_show();
			},
			public_validate() {
				let that = this;
				let errmsg = null;
				let value = that.field.__answer__.value ? that.field.__answer__.value : "";

				if (that.field.csmwjrequired && value == "") {
					errmsg = that.$t("xc.rules_required_input");
					return errmsg;
				}
				//TODO

				return errmsg;
			},
			control_change() {
				let that = this;
				that.$emit("change");
				that.field.errmsg = that.public_validate();
			},
		}
	}
</script>

<style lang="scss">

</style>